package com.ysd.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ysd.entity.Verification;
import com.ysd.service.VerificationService;
import com.ysd.util.Result;

@Controller
public class VerificationController {

	@Autowired
	private VerificationService verificationService;

	/**
	 * 发送重置密码的验证码
	 * 
	 * @param email
	 * @return
	 */

	@RequestMapping("sendResetPasswordCode")
	@ResponseBody
	public Object sendResetPasswordCode(String email) {
		Verification v = new Verification();
		v.setV_email(email);
		if (email != null) { // 发送验证码
			int n = verificationService.saveResetPasswordCode(v);
			if (n > 0) {
				return Result.toClient("0", "发送成功", null);
			} else {
				return Result.toClient("1", "发送失败", null);
			}

		} else {
			return Result.toClient("1", "接口调用错误", null);
		}
	}
	
	@RequestMapping("selEmail")
	@ResponseBody
	public Object selEmail(Verification verification) {
		Verification v = verificationService.findEmail(verification);
		if (v != null) {
			return Result.toClient("0", "查询成功", v);
		} else {
			return Result.toClient("1", "查询失败", null);
		}
	}
	
	@RequestMapping("updaSta")
	@ResponseBody
	public Object updaSta(Verification verification) {
		int n = verificationService.findSta(verification);
		if (n>0) {
			return Result.toClient("0", "修改成功", n);
		} else {
			return Result.toClient("1", "修改失败", null);
		}
	}
}